Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

196
Visualizações
Getting Error: "TypeError: Cannot read property 'channels' of undefined"

Here's my code:

module.exports = {
    name: 'suggestions',
    aliases: ['suggest'],
    execute(message, args, cmd, client, discord) {
        let channel = message.guild.channel.cache.find(ch=>ch.id==='890313569260937247')
        if(!channel) return message.channel.send({ content: 'There is no suggestion channel on this Server!' });

        let messageArgs = args.join(' ')
        const embed = new Discord.MessageEmbed()
        .setColor('#008000')
        .setAuthor(message.author.tag)
        .setDescription(messageArgs)
        .setTitle(`${message.author.tag} has a suggestion!!`)

        message.channel.send({ embeds: [embed] })
    }
}

I'm basically creating a command with my command Handler, doing a suggestion command, where the arguments of an user are going to be sent in a MessageEmbed.

If I run the actual command, this error shows up:

TypeError: Cannot read property 'channel' of undefined
    at Object.execute (D:\Programming\Workspaces\Discord Bots\Mita Bot v1\commands\suggestions.js:5:37)
    at module.exports (D:\Programming\Workspaces\Discord Bots\Mita Bot v1\events\guild\message.js:11:25)
    at Client.emit (node:events:394:28)
    at MessageCreateAction.handle (D:\Programming\Workspaces\Discord Bots\Mita Bot v1\node_modules\discord.js\src\client\actions\MessageCreate.js:31:18)
    at Object.module.exports [as MESSAGE_CREATE] (D:\Programming\Workspaces\Discord Bots\Mita Bot v1\node_modules\discord.js\src\client\websocket\handlers\MESSAGE_CREATE.js:4:32)
    at WebSocketManager.handlePacket (D:\Programming\Workspaces\Discord Bots\Mita Bot v1\node_modules\discord.js\src\client\websocket\WebSocketManager.js:345:31)
    at WebSocketShard.onPacket (D:\Programming\Workspaces\Discord Bots\Mita Bot v1\node_modules\discord.js\src\client\websocket\WebSocketShard.js:443:22)
    at WebSocketShard.onMessage (D:\Programming\Workspaces\Discord Bots\Mita Bot v1\node_modules\discord.js\src\client\websocket\WebSocketShard.js:300:10)
    at WebSocket.onMessage (D:\Programming\Workspaces\Discord Bots\Mita Bot v1\node_modules\discord.js\node_modules\ws\lib\event-target.js:132:16)
    at WebSocket.emit (node:events:394:28)
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

As t.niese said in their comment, Message#guild can be null. If message.guild === null, this means the message was sent in a DM.

Check if the message was sent in a guild first:

if (!message.guild)
  return message.channel.send('This command can only be used in a server!')

const channel = message.guild.channels.get('890313569260937247')
if (!channel)
  return message.channel.send('There is no suggestion channel on this Server!')

Some other points:

  • There is no channel property on Guild; use channels instead.
  • You can use Collection#get to get a channel by its id (no need to use .find(c => c.id === someId).
  • You can use a string directly in send: channel.send('the message') instead of channel.send({ content: 'the message' }).
about 4 years ago · Juan Pablo Isaza Relatório

0

'channel' is not a property of the Guild class, you probably meant Guild#channels which returns the necessary type of GuildChannelManager.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda